import numpy as np
import pandas as pd
import webbrowser


def main():
    link = 'https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html'
    # webbrowser.open(link)
    df1 = pd.read_clipboard()
    print(df1)

    # 默认有index，index为False，则不加
    # df1.to_csv('df1.csv', index=False)


    df2 = pd.read_csv('df1.csv')
    print(df2)

    print(df1.to_json())

    df1.to_excel('df1.xlsx', index=False)

    # 默认取前5条，可以传数字
    df1.head()
    # 默认取后5条，可以传数字
    df1.tail()

    # 选两列的话，需要加上[]，一列不用
    print(df2[['Reader', 'Writer']])

    # 取元素两种，iloc和loc
    # 行取5-9行，列取0列，含前不含后
    '''
    Format Type
    5      binary
    6      binary
    7      binary
    8      binary
    9      binary
    '''
    print(df2.iloc[5: 10, :1])
    # 这个和上面的不同，上面是index，这个是label，和label严格对应，哪怕截取了
    '''
           Data Description       Reader     Writer
    11                   SAS     read_sas           
    12  Python Pickle Format  read_pickle  to_pickle
    13                   SQL     read_sql     to_sql
    '''
    print(df2.loc[11: 13, 'Data Description':])


if __name__ == '__main__':
    main()
